package com.haierCamera.customapplication.ui.main.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.haierCamera.customapplication.R;

import androidx.annotation.NonNull;

public class DialogDeviceNotSupportWifi extends Dialog implements View.OnClickListener {
    //声明xml文件里的组件
    private ImageView iv_close;
    private Activity activity;

    private IOnCancelListener cancelListener;


    public void setCancel(IOnCancelListener cancelListener) {
        this.cancelListener=cancelListener;
    }


    //CustomDialog类的构造方法
    public DialogDeviceNotSupportWifi(@NonNull Context context) {
        super(context);
    }
    public DialogDeviceNotSupportWifi(@NonNull Context context, int themeResId, Activity activity) {
        super(context, themeResId);
        this.activity = activity;
    }

    //在app上以对象的形式把xml里面的东西呈现出来的方法！
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //为了锁定app界面的东西是来自哪个xml文件
        setContentView(R.layout.hzkl_dialog_not_support_wifi);
        iv_close = findViewById(R.id.iv_close);

        //为两个按钮添加点击事件
        iv_close.setOnClickListener(this);
        setCanceledOnTouchOutside(false);//外部点击取消
        setViewLocation();
    }


    private void setViewLocation(){
        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        int height = dm.heightPixels;

        Window window = this.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.x = 0;
        lp.y = height;
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // 设置显示位置
        onWindowAttributesChanged(lp);
    }



    //重写onClick方法
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_close:
                if(cancelListener!=null){
                    cancelListener.onCancel(this);
                }
                dismiss();
                break;

        }
    }

    //写两个接口，当要创建一个CustomDialog对象的时候，必须要实现这两个接口
    //也就是说，当要弹出一个自定义dialog的时候，取消和确定这两个按钮的点击事件，一定要重写！
    public interface IOnCancelListener{
        void onCancel(DialogDeviceNotSupportWifi dialog);
    }

}
